// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2010-5-13 14:49:05
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   AuthoritiesAction.java

package com.stnet.web.enterprice.system;

import java.net.URLDecoder;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.modules.commons.PageAction;
import com.stnet.entity.Authorities;

public class AuthoritiesAction extends PageAction
{

    public AuthoritiesAction()
    {
        authorities = new Authorities();
    }

    public String execute()
        throws Exception
    {
        super.pager = authoritiesManagerDao.findAuthorities(pageSize, pageNo, "-1");
        authoritiesList = super.pager.getResultList();
        return "success";
    }

    public String view()
        throws Exception
    {
        authorities = authoritiesManagerDao.getAuthorities(id);
        return "view";
    }

    public String edit()
        throws Exception
    {
        setAuthorities(authoritiesManagerDao.getAuthorities(id));
        return "edit";
    }

    public String checkName()
        throws Exception
    {
        HttpServletRequest request = ServletActionContext.getRequest();
        String name = request.getParameter("name");
        String orgName = request.getParameter("orgName");
        name = URLDecoder.decode(name, "UTF-8");
        orgName = URLDecoder.decode(orgName, "UTF-8");
        if(authoritiesManagerDao.isNameUnique(name, orgName))
            return renderText("true");
        else
            return renderText("false");
    }

    public String checkDisplayName()
        throws Exception
    {
        HttpServletRequest request = ServletActionContext.getRequest();
        String displayName = request.getParameter("displayName");
        String orgName = request.getParameter("orgName");
        displayName = URLDecoder.decode(displayName, "UTF-8");
        orgName = URLDecoder.decode(orgName, "UTF-8");
        if(authoritiesManagerDao.isDisplayNameUnique(displayName, orgName))
            return renderText("true");
        else
            return renderText("false");
    }

    public String update()
        throws Exception
    {
        initAuthorities();
        authoritiesManagerDao.updateAuthorities(authorities);
        return "update";
    }

    public String add_page()
        throws Exception
    {
        return "add_page";
    }

    public String add()
        throws Exception
    {
        initAuthorities();
        authoritiesManagerDao.addAuthorities(authorities);
        return "add";
    }

    public String delete()
        throws Exception
    {
        authoritiesManagerDao.deleteAuthorities(id);
        return "delete";
    }

    public void initAuthorities()
    {
        authorities.setName(name);
        authorities.setDisplayName(displayName);
    }

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Authorities getAuthorities()
    {
        return authorities;
    }

    public void setAuthorities(Authorities authorities)
    {
        this.authorities = authorities;
    }

    public List getAuthoritiesList()
    {
        return authoritiesList;
    }

    public void setAuthoritiesList(List authoritiesList)
    {
        this.authoritiesList = authoritiesList;
    }

    public String getDisplayName()
    {
        return displayName;
    }

    public void setDisplayName(String displayName)
    {
        this.displayName = displayName;
    }

    private Authorities authorities;
    private List authoritiesList;
    private Long id;
    private String name;
    private String displayName;
}